<script>
import {reactive} from "vue"
import {useRouter} from "vue-router"
import {getJsonshop} from '../api/shop.js'
import BomNav from "../components/BomNav.vue";
export default {
    components: {
    BomNav,
  },
    setup() {
        let router = useRouter()
        // let route = useRoute()
        let data = reactive({
            shopList:[]
        })
        getJsonshop().then(data1=>{
            data.shopList=data1.data
        })
        let goods = (shopid) =>{
            console.log(shopid);
            router.push({
                   path:"/shopDetail",
                   query:{
                        shopid
                    }
            })

        }
        return {
            data,
            goods
        }
    },
}
</script>

<template>
    <div class="shop" >
        <div class="wrapper">
            <!-- 头部 -->
            <div class="header">
                <div class="header_center"><strong>终点商城</strong></div>
            </div>

            <!-- 分类 -->
            <!-- <div class="type">
                <ul>
                    <li v-for="item in lists" :key="item.id" >
                        <img :src="item.img" alt="">
                        <p>{{item.title}}</p>
                    </li>
                </ul>
            </div> -->

            <!-- 商品列表 -->
            <div class="shopList">
                <h4>精选书籍</h4>

                <ul>
                    <li v-for="item in data.shopList" :key="item.shopid" @click="goods(item.shopid)">
                        <div class="img">
                            <img :src="item.url" alt="">
                            <div class="freeship" v-if="item.free">精选</div>
                        </div>
                        <!-- <p class="tip">{{item.tip}}</p> -->
                        <p class="title">{{item.title}}</p>
                        <div class="price">
                            <div class="newprice">￥{{item.newprice}}</div>
                            <div class="oldprice"><del>￥{{item.oldprice}}</del></div>
                        </div>
                    </li>
                    
                </ul>

            </div>
        </div>
    </div>
     <BomNav />
</template>

<style lang="scss" scoped>
.shop{
    .wrapper{
        width: 100%;
        height: calc(100vh - 55px);
        overflow: auto;
        .header{
            position: fixed;
            top: 0;
            left: 0;
            background-color: #fff;
            z-index: 1;
            width: 100%;
            // padding: 0 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 43px;
            box-shadow: 0px 2px 5px #f2f3f3;
            .header_left{
                font-size: 22px;
                padding: 0 16px;
            }
            // .header_center{}
            .header_right{
                padding: 0 16px;
                font-size: 22px;
                position: relative;
                span{
                    position: absolute;
                    top: -3px;
                    right: 12px;
                    font-size: 10px;
                    width: 15px;
                    height: 15px;
                    color: #fff;
                    text-align: center;
                    border-radius: 50%;
                    background-color: #de2e20;
                }
            }
        }
        .type{
            margin-top: 52px;
            &>ul{
                display: flex;
                flex-wrap: wrap;
                align-items: center;
                &>li{
                    // height: 52px;
                    width: 20%;
                    padding-top: 7px;
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    img{
                        height: 35px;
                    }
                    p{
                        font-size: 10px;
                        padding: 2px 0 6px 0;
                    }
                }
            }
        }
        .shopList{
            padding: 0 16px 52px;

            margin-top: 44px;
            & > h4{
                height: 36px;
                line-height: 36px;
                font-weight: 500;
                font-style: italic;
            }
             ul{
                width: 100%;
                display: flex;
                flex-wrap: wrap;
                & > li{
                    width: calc(50% - 5.5px);
                    margin-bottom: 36px;
                    margin-right: 11px;
                    &:nth-child(2n){
                        margin-right: 0;
                    }
                    & > .img{
                        width: 100%;
                        position: relative;
                        img{
                            width: 100%;
                            border-top-left-radius: 8px;
                            border-top-right-radius: 8px;
                        }
                        .freeship{
                            position: absolute;
                            top: 8px;
                            left: 8px;
                            font-size: 10px;
                            transform: scale(0.9);
                            color: #fff;
                            background-color: #ff9728;
                            padding: 3px 5px;
                            border-radius: 6px;
                        }
                    }
                    .tip{
                        padding: 0 8px;
                        height: 32px;
                        line-height: 32px;
                        background-color: #f9f2e5;
                        border-bottom-left-radius: 8px;
                        border-bottom-right-radius: 8px;
                        color: white;
                        font-weight: 800;
                        font-size: 10px;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                    }
                    .title{
                        font-size: 11px;
                        padding: 7px 0px 0 0;
                        font-weight: 800;
                        height: 33px;
                        display: -webkit-box;
                        -webkit-box-orient: vertical;
                        -webkit-line-clamp: 2;
                        overflow: hidden;
                    }
                    .price{
                        display: flex;
                        align-items: flex-end;
                        padding: 4px 0;
                        .newprice{
                            font-size: 15px;
                            color: #ff9728;
                            font-weight: 800;
                        }
                        .oldprice{
                            transform: scale(0.9);
                            font-size: 10px;
                            color: #aaa;
                        }
                    }
                }
            }
        }
    }
}
</style>